__author__ = 'kent'
#!coding=utf-8
from django.shortcuts import *
import json,random,time,os
from models import *
from settings import STATIC_ROOT,SITE_ROOT
from django.views.decorators.csrf import csrf_exempt
import simplejson
import sys
reload(sys)
sys.setdefaultencoding('utf8')
from util.form_util  import *
def lawDetail(request):
    _enterPrise = request.session.get('ep')
    fillModel=request.session['fill']
    appModel=Application_status.objects.filter(fill=fillModel,enterprise=_enterPrise,app_name="法律法规遵守情况")
    if appModel:
        appModel=appModel[0]
    list_1=Licenses.objects.filter(enterprise = _enterPrise,type=1,application_status=appModel)
    submit_type=''
    if list_1:
        status_1=list_1[0].submit_type
        if list_1[0].submit_type=='1':
            submit_type='1'
        else:
            submit_type='2'
    else:
        status_1=''
    list_1=Licenses.objects.filter(enterprise = _enterPrise,type=1,application_status=appModel)
    list_2=Licenses.objects.filter(enterprise = _enterPrise,type=2,application_status=appModel)
    list_3=Licenses.objects.filter(enterprise = _enterPrise,type=3,application_status=appModel)
    list_4=Licenses.objects.filter(enterprise = _enterPrise,type=4,application_status=appModel)
    list_5=Licenses.objects.filter(enterprise = _enterPrise,type=5,application_status=appModel)
    list_6=Licenses.objects.filter(enterprise = _enterPrise,type=6,application_status=appModel)
    list_7=Licenses.objects.filter(enterprise = _enterPrise,type=7,application_status=appModel)
    list_8=Licenses.objects.filter(enterprise = _enterPrise,type=8,application_status=appModel)
    list_9=Licenses.objects.filter(enterprise = _enterPrise,type=9,application_status=appModel)
    remark_1=Law_remark.objects.filter(enterprise=_enterPrise,type=1)
    remark_2=Law_remark.objects.filter(enterprise=_enterPrise,type=2)
    files_1=Law_files.objects.filter(enterprise=_enterPrise,type=1)
    files_2=Law_files.objects.filter(enterprise=_enterPrise,type=2)
    files_3=Law_files.objects.filter(enterprise=_enterPrise,type=3)
    poll_1=Emissions.objects.filter(enterprise=_enterPrise,type=1,application_status=appModel)
    if poll_1:
        poll1_length=len(poll_1)
        status_2=poll_1[0].submit_type
    else:
        status_2=''
        poll1_length=0
    poll_2=Emissions.objects.filter(enterprise=_enterPrise,type=2,application_status=appModel)
    poll_3=Emissions.objects.filter(enterprise=_enterPrise,type=3,application_status=appModel)
    clean=Cleaner_production.objects.filter(enterprise=_enterPrise,application_status=appModel)
    template='enterprise/basic_information/laws/basic_laws_detail.html'
    if remark_1:
        remark_1=remark_1[0]
    if remark_2:
        remark_2=remark_2[0]
    if clean:
        clean=clean[0]
    else:
        clean=None
    emergencies = Environmental_emergencies.objects.filter(enterprise = _enterPrise,application_status=appModel)
    if emergencies:
        emer = emergencies[0]
    else:
        emer = Environmental_emergencies()
    status=appModel.app_status
    # status=emer.application_status
    params={  'list_1':list_1,'one_length':len(list_1) ,
              'list_2':list_2,'two_length':len(list_2),
              'list_3':list_3,'three_length':len(list_3),
              'list_4':list_4,'four_length':len(list_4),
              'list_5':list_5,'five_length':len(list_5),
              'list_6':list_6,'six_length':len(list_6),
              'list_7':list_7,'seven_length':len(list_7),
              'list_8':list_8,'eight_length':len(list_8),
              'list_9':list_9,'nine_length':len(list_9),
              'poll_1':poll_1,'poll_2':poll_2,'poll1_length':poll1_length,
              'poll_3':poll_3,'poll2_length':len(poll_2),
              'emer':emer,'poll3_length':len(poll_3),
              'remark_1':remark_1,
              'remark_2':remark_2,
              'files_1':files_1,
              'files_2':files_2,
              'files_3':files_3,
              'file1_length':len(files_1),
              'file2_length':len(files_2),
              'file3_length':len(files_3),
              'clean':clean,
              'status_1':status_1,
              'status_2':status_2,
              'status':status,
              'fillModel':fillModel.status,
              }
    return render_to_response(template,params ,context_instance=RequestContext(request))
'''
1、获得的行政许可情况
'''
@csrf_exempt
def basic_laws_license(request):
    _enterPrise = request.session.get('ep')
    fillModel=request.session['fill']
    appModel=Application_status.objects.filter(fill=fillModel,enterprise=_enterPrise,app_name="法律法规遵守情况")
    if appModel:
        appModel=appModel[0]
    if request.method=='GET':
        list_1=Licenses.objects.filter(enterprise = _enterPrise,type=1,application_status=appModel)
        list_2=Licenses.objects.filter(enterprise = _enterPrise,type=2,application_status=appModel)
        list_3=Licenses.objects.filter(enterprise = _enterPrise,type=3,application_status=appModel)
        list_4=Licenses.objects.filter(enterprise = _enterPrise,type=4,application_status=appModel)
        list_5=Licenses.objects.filter(enterprise = _enterPrise,type=5,application_status=appModel)
        list_6=Licenses.objects.filter(enterprise = _enterPrise,type=6,application_status=appModel)
        list_7=Licenses.objects.filter(enterprise = _enterPrise,type=7,application_status=appModel)
        list_8=Licenses.objects.filter(enterprise = _enterPrise,type=8,application_status=appModel)
        list_9=Licenses.objects.filter(enterprise = _enterPrise,type=9,application_status=appModel)
        remark_1=Law_remark.objects.filter(enterprise=_enterPrise,type=1)
        if remark_1:
            remark_1=remark_1[0]
        params={  'list_1' : list_1,'one_length':len(list_1) ,
                  'list_2':list_2,'two_length':len(list_2),
                  'list_3':list_3,'three_length':len(list_3),
                  'list_4':list_4,'four_length':len(list_4),
                  'list_5':list_5,'five_length':len(list_5),
                  'list_6':list_6,'six_length':len(list_6),
                  'list_7':list_7,'seven_length':len(list_7),
                  'list_8':list_8,'eight_length':len(list_8),
                  'list_9':list_9,'nine_length':len(list_9),
                  'remark_1':remark_1,
                  }

        return render_to_response('enterprise/basic_information/laws/basic_laws_license.html',params ,context_instance=RequestContext(request))
    if request.method=='POST':

        serial_number_1=request.POST.getlist('serial_number_1')
        issuing_authority_1=request.POST.getlist('issuing_authority_1')
        expiration_1=request.POST.getlist('expiration_1')
        oldfiles1=request.POST.getlist('oldfile1')
        files1= request.FILES.getlist('file1','')
        remark1=request.POST.getlist('remark1')

        serial_number_2=request.POST.getlist('serial_number_2')
        issuing_authority_2=request.POST.getlist('issuing_authority_2')
        expiration_2=request.POST.getlist('expiration_2')
        oldfiles2=request.POST.getlist('oldfile2')
        files2= request.FILES.getlist('file2','')
        remark2=request.POST.getlist('remark2')

        serial_number_3=request.POST.getlist('serial_number_3')
        issuing_authority_3=request.POST.getlist('issuing_authority_3')
        expiration_3=request.POST.getlist('expiration_3')
        oldfiles3=request.POST.getlist('oldfile3')
        files3= request.FILES.getlist('file3','')
        remark3=request.POST.getlist('remark3')

        serial_number_4=request.POST.getlist('serial_number_4')
        issuing_authority_4=request.POST.getlist('issuing_authority_4')
        expiration_4=request.POST.getlist('expiration_4')
        oldfiles4=request.POST.getlist('oldfile4')
        files4= request.FILES.getlist('file4','')
        remark4=request.POST.getlist('remark4')

        serial_number_5=request.POST.getlist('serial_number_5')
        issuing_authority_5=request.POST.getlist('issuing_authority_5')
        expiration_5=request.POST.getlist('expiration_5')
        oldfiles5=request.POST.getlist('oldfile5')
        files5= request.FILES.getlist('file5','')
        remark5=request.POST.getlist('remark5')

        serial_number_6=request.POST.getlist('serial_number_6')
        issuing_authority_6=request.POST.getlist('issuing_authority_6')
        expiration_6=request.POST.getlist('expiration_6')
        oldfiles6=request.POST.getlist('oldfile6')
        files6= request.FILES.getlist('file6','')
        remark6=request.POST.getlist('remark6')

        serial_number_7=request.POST.getlist('serial_number_7')
        issuing_authority_7=request.POST.getlist('issuing_authority_7')
        expiration_7=request.POST.getlist('expiration_7')
        oldfiles7=request.POST.getlist('oldfile7')
        files7= request.FILES.getlist('file7','')
        remark7=request.POST.getlist('remark7')

        serial_number_8=request.POST.getlist('serial_number_8')
        issuing_authority_8=request.POST.getlist('issuing_authority_8')
        expiration_8=request.POST.getlist('expiration_8')
        oldfiles8=request.POST.getlist('oldfile8')
        files8= request.FILES.getlist('file8','')
        remark8=request.POST.getlist('remark8')

        serial_number_9=request.POST.getlist('serial_number_9')
        issuing_authority_9=request.POST.getlist('issuing_authority_9')
        expiration_9=request.POST.getlist('expiration_9')
        oldfiles9=request.POST.getlist('oldfile9')
        files9= request.FILES.getlist('file9','')
        remark9=request.POST.getlist('remark9')
        try:
            key= request.GET['key']
            mangsave(len(serial_number_1),1,_enterPrise,serial_number_1,issuing_authority_1,expiration_1,oldfiles1,files1,remark1,appModel,submit_type='2')
            mangsave(len(serial_number_2),2,_enterPrise,serial_number_2,issuing_authority_2,expiration_2,oldfiles2,files2,remark2,appModel,submit_type='2')
            mangsave(len(serial_number_3),3,_enterPrise,serial_number_3,issuing_authority_3,expiration_3,oldfiles3,files3,remark3,appModel,submit_type='2')
            mangsave(len(serial_number_4),4,_enterPrise,serial_number_4,issuing_authority_4,expiration_4,oldfiles4,files4,remark4,appModel,submit_type='2')
            mangsave(len(serial_number_5),5,_enterPrise,serial_number_5,issuing_authority_5,expiration_5,oldfiles5,files5,remark5,appModel,submit_type='2')
            mangsave(len(serial_number_6),6,_enterPrise,serial_number_6,issuing_authority_6,expiration_6,oldfiles6,files6,remark6,appModel,submit_type='2')
            mangsave(len(serial_number_7),7,_enterPrise,serial_number_7,issuing_authority_7,expiration_7,oldfiles7,files7,remark7,appModel,submit_type='2')
            mangsave(len(serial_number_8),8,_enterPrise,serial_number_8,issuing_authority_8,expiration_8,oldfiles8,files8,remark8,appModel,submit_type='2')
            mangsave(len(serial_number_9),9,_enterPrise,serial_number_9,issuing_authority_9,expiration_9,oldfiles9,files9,remark9,appModel,submit_type='2')
            appModel.app_status="未确认"
            appModel.save()
        except Exception as e:
            mangsave(len(serial_number_1),1,_enterPrise,serial_number_1,issuing_authority_1,expiration_1,oldfiles1,files1,remark1,appModel,submit_type='1')
            mangsave(len(serial_number_2),2,_enterPrise,serial_number_2,issuing_authority_2,expiration_2,oldfiles2,files2,remark2,appModel,submit_type='1')
            mangsave(len(serial_number_3),3,_enterPrise,serial_number_3,issuing_authority_3,expiration_3,oldfiles3,files3,remark3,appModel,submit_type='1')
            mangsave(len(serial_number_4),4,_enterPrise,serial_number_4,issuing_authority_4,expiration_4,oldfiles4,files4,remark4,appModel,submit_type='1')
            mangsave(len(serial_number_5),5,_enterPrise,serial_number_5,issuing_authority_5,expiration_5,oldfiles5,files5,remark5,appModel,submit_type='1')
            mangsave(len(serial_number_6),6,_enterPrise,serial_number_6,issuing_authority_6,expiration_6,oldfiles6,files6,remark6,appModel,submit_type='1')
            mangsave(len(serial_number_7),7,_enterPrise,serial_number_7,issuing_authority_7,expiration_7,oldfiles7,files7,remark7,appModel,submit_type='1')
            mangsave(len(serial_number_8),8,_enterPrise,serial_number_8,issuing_authority_8,expiration_8,oldfiles8,files8,remark8,appModel,submit_type='1')
            mangsave(len(serial_number_9),9,_enterPrise,serial_number_9,issuing_authority_9,expiration_9,oldfiles9,files9,remark9,appModel,submit_type='1')
            appModel.app_status="已确认"
            appModel.save()
        return HttpResponseRedirect('/basic/law/detail/')

def mangsave(one_number,type,_enterPrise,serial_number_1,issuing_authority_1,expiration_1,oldfiles1,files1,remark,appModel,submit_type):
    # licenses=Licenses.objects.filter(enterprise=_enterPrise,application_status=appModel,type=type)
    for number in range(one_number):
        licenses=Licenses()
        licenses.enterprise=_enterPrise
        licenses.serial_number=serial_number_1[number]
        licenses.issuing_authority=issuing_authority_1[number]
        licenses.expiration=expiration_1[number]
        licenses.remark=remark[number]
        licenses.submit_type=submit_type
        licenses.application_status=appModel
        licenses.type=type
        if files1:
            try:
                f_name=files1[number].name.split('/')[-1]
                if f_name not in oldfiles1:
                    licenses.upload_file_name=f_name
                    licenses.upload_file=files1[number]
                    licenses.save()
            except Exception as e:
                pass
'''
2、污染物达标排放情况
'''

@csrf_exempt
def basic_laws_pollution(request):
    _enterPrise = request.session.get('ep')
    fillModel=request.session['fill']
    appModel=Application_status.objects.filter(fill=fillModel,enterprise=_enterPrise,app_name="法律法规遵守情况")
    if appModel:
        appModel=appModel[0]
    if request.method=="GET":
        list_1=Emissions.objects.filter(enterprise = _enterPrise,type=1,application_status=appModel)
        list_2=Emissions.objects.filter(enterprise = _enterPrise,type=2,application_status=appModel)
        list_3=Emissions.objects.filter(enterprise = _enterPrise,type=3,application_status=appModel)
        remark_2=Law_remark.objects.filter(enterprise=_enterPrise,type=2)
        law_files=Law_files.objects.filter(enterprise=_enterPrise,type=2)
        if remark_2:
            remark_2=remark_2[0]
        params={  'list_1' : list_1,'one_length':len(list_1) ,
              'list_2':list_2,'two_length':len(list_2),
              'list_3':list_3,'three_length':len(list_3),
              'remark_2':remark_2,
              'law_files':law_files,
              }
        return render_to_response('enterprise/basic_information/laws/basic_laws_pollution.html',params ,context_instance=RequestContext(request))
    if request.method=="POST":
        key= request.GET['key']
        Emissions.objects.filter(enterprise=_enterPrise,application_status=appModel).delete()
        Law_remark.objects.filter(enterprise=_enterPrise,type=2).delete()
        name1=request.POST.getlist('name1')
        name2=request.POST.getlist('name2')
        name3=request.POST.getlist('name3')
        code1=request.POST.getlist('code1')
        code2=request.POST.getlist('code2')
        code3=request.POST.getlist('code3')
        status1=request.POST.getlist('status1')
        status2=request.POST.getlist('status2')
        status3=request.POST.getlist('status3')
        level1=request.POST.getlist('level1')
        level2=request.POST.getlist('level2')
        level3=request.POST.getlist('level3')
        sm1=request.POST.getlist('sm1')
        sm2=request.POST.getlist('sm2')
        sm3=request.POST.getlist('sm3')
        remark=request.POST.get('remark')
        files=request.FILES.getlist('file','')
        oldfiles=request.POST.getlist('oldfile')
        law_files=Law_files.objects.filter(enterprise=_enterPrise,type=2)
        for file in law_files:
            if file.file_name not in oldfiles:
                ipath=SITE_ROOT+'/'+(file.upload_file.name)
                os.remove(unicode( ipath, "utf8" ) )
                file.delete()
        for file in files:
            file_name=file.name.split('/')[-1]
            Law_files.objects.create(enterprise=_enterPrise,upload_file=file,type=2,file_name=file_name)
        poll(len(name1),1,_enterPrise,name1,code1,status1,level1,sm1,appModel,submit_type='2')
        poll(len(name2),2,_enterPrise,name2,code2,status2,level2,sm2,appModel,submit_type='2')
        poll(len(name3),3,_enterPrise,name3,code3,status3,level3,sm3,appModel,submit_type='2')
        appModel.app_status="未确认"
        appModel.save()
        if(remark):
            Law_remark.objects.create(remark=remark,enterprise=_enterPrise,type=2)
        return HttpResponseRedirect('/basic/law/detail/')

@csrf_exempt
def submit_pollution(request):
    _enterPrise = request.session.get('ep')
    fillModel=request.session['fill']
    appModel=Application_status.objects.filter(fill=fillModel,enterprise=_enterPrise,app_name="法律法规遵守情况")
    if appModel:
        appModel=appModel[0]
    Emissions.objects.filter(enterprise=_enterPrise).delete()
    Law_remark.objects.filter(enterprise=_enterPrise,type=2).delete()
    name1=request.POST.getlist('name1')
    name2=request.POST.getlist('name2')
    name3=request.POST.getlist('name3')
    code1=request.POST.getlist('code1')
    code2=request.POST.getlist('code2')
    code3=request.POST.getlist('code3')
    status1=request.POST.getlist('status1')
    status2=request.POST.getlist('status2')
    status3=request.POST.getlist('status3')
    level1=request.POST.getlist('level1')
    level2=request.POST.getlist('level2')
    level3=request.POST.getlist('level3')
    sm1=request.POST.getlist('sm1')
    sm2=request.POST.getlist('sm2')
    sm3=request.POST.getlist('sm3')
    remark=request.POST.get('remark')
    files=request.FILES.getlist('file','')
    oldfiles=request.POST.getlist('oldfile')
    law_files=Law_files.objects.filter(enterprise=_enterPrise,type=2)
    for file in law_files:
        if file.file_name not in oldfiles:
            ipath=SITE_ROOT+'/'+(file.upload_file.name)
            os.remove(unicode( ipath, "utf8" ) )
            file.delete()
    for file in files:
        file_name=file.name.split('/')[-1]
        Law_files.objects.create(enterprise=_enterPrise,upload_file=file,type=2,file_name=file_name)
    poll(len(name1),1,_enterPrise,name1,code1,status1,level1,sm1,appModel,submit_type='1')
    poll(len(name2),2,_enterPrise,name2,code2,status2,level2,sm2,appModel,submit_type='1')
    poll(len(name3),3,_enterPrise,name3,code3,status3,level3,sm3,appModel,submit_type='1')
    if(remark):
        Law_remark.objects.create(remark=remark,enterprise=_enterPrise,type=2)
    return HttpResponseRedirect('/basic/law/detail/')

def poll(one_number,type,_enterPrise,name,code,status,level,sm,appModel,submit_type):
    for number in range(one_number):
        emissions=Emissions()
        emissions.name=name[number]
        emissions.code=code[number]
        emissions.status=status[number]
        emissions.level=level[number]
        emissions.enterprise=_enterPrise
        emissions.type=type
        emissions.application_status=appModel
        emissions.submit_type=submit_type
        emissions.sm=sm[number]
        emissions.save()
'''
3、清洁生产审核情况
'''
@csrf_exempt
def basic_laws_clean(request):
    _enterPrise = request.session.get('ep')
    fillModel=request.session['fill']
    appModel=Application_status.objects.filter(fill=fillModel,enterprise=_enterPrise,app_name="法律法规遵守情况")
    if appModel:
        appModel=appModel[0]
    if request.method=='GET':
        clean=Cleaner_production.objects.filter(enterprise=_enterPrise,application_status=appModel)
        law_files=Law_files.objects.filter(enterprise=_enterPrise,type=3)
        if clean:
            clean=clean[0]
        params={
            'clean':clean,
            'law_files':law_files,
            }
        return render_to_response('enterprise/basic_information/laws/basic_laws_clean.html',params ,context_instance=RequestContext(request))
    if request.method=='POST':
        key= request.GET['key']
        Cleaner_production.objects.filter(enterprise=_enterPrise,application_status=appModel).delete()
        law_files=Law_files.objects.filter(enterprise=_enterPrise,type=3)
        enforcement=request.POST.get('enforcement')
        launch=request.POST.get('launch')
        evaluation=request.POST.get('evaluation')
        acceptance=request.POST.get('acceptance')
        most_recently=request.POST.get('most_recently')
        department=request.POST.get('department')
        remark=request.POST.get('remark')
        files=request.FILES.getlist('file','')
        oldfiles=request.POST.getlist('oldfile')
        for file in law_files:
            if file.file_name not in oldfiles:
                # ipath=SITE_ROOT+'/'+(file.upload_file.name)
                # os.remove(unicode( ipath, "utf8" ) )
                file.delete()
        for file in files:
            file_name=file.name.split('/')[-1]
            Law_files.objects.create(enterprise=_enterPrise,upload_file=file,type=3,file_name=file_name)
        cleaner_production=Cleaner_production()
        cleaner_production.remark=remark
        cleaner_production.enterprise=_enterPrise
        cleaner_production.acceptance=acceptance
        cleaner_production.evaluation=evaluation
        cleaner_production.department=department
        cleaner_production.most_recently=most_recently
        cleaner_production.launch=launch
        cleaner_production.enforcement=enforcement
        cleaner_production.application_status=appModel
        cleaner_production.submit_type='2'
        appModel.app_status="未确认"
        appModel.save()
        cleaner_production.save()
        return HttpResponseRedirect('/basic/law/detail/')


@csrf_exempt
def submit_clean(request):
    _enterPrise = request.session.get('ep')
    fillModel=request.session['fill']
    appModel=Application_status.objects.filter(fill=fillModel,enterprise=_enterPrise,app_name="法律法规遵守情况")
    if appModel:
        appModel=appModel[0]
    Cleaner_production.objects.filter(enterprise=_enterPrise,application_status=appModel).delete()
    law_files=Law_files.objects.filter(enterprise=_enterPrise,type=3)
    enforcement=request.POST.get('enforcement')
    launch=request.POST.get('launch')
    evaluation=request.POST.get('evaluation')
    acceptance=request.POST.get('acceptance')
    most_recently=request.POST.get('most_recently')
    department=request.POST.get('department')
    remark=request.POST.get('remark')
    files=request.FILES.getlist('file','')
    oldfiles=request.POST.getlist('oldfile')
    for file in law_files:
        if file.file_name not in oldfiles:
            # ipath=SITE_ROOT+'/'+(file.upload_file.name)
            # os.remove(unicode( ipath, "utf8" ) )
            file.delete()
    for file in files:
        file_name=file.name.split('/')[-1]
        Law_files.objects.create(enterprise=_enterPrise,upload_file=file,type=3,file_name=file_name)
    cleaner_production=Cleaner_production()
    cleaner_production.remark=remark
    cleaner_production.enterprise=_enterPrise
    cleaner_production.acceptance=acceptance
    cleaner_production.evaluation=evaluation
    cleaner_production.department=department
    cleaner_production.most_recently=most_recently
    cleaner_production.launch=launch
    cleaner_production.enforcement=enforcement
    cleaner_production.application_status=appModel
    cleaner_production.submit_type='1'
    cleaner_production.save()
    return HttpResponseRedirect('/basic/law/detail/')

'''
4、应急预案及突发环境事件
'''
@csrf_exempt
def basic_laws_emergency(request):
    _enterPrise = request.session.get('ep')
    fillModel=request.session['fill']
    appModel=Application_status.objects.filter(fill=fillModel,enterprise=_enterPrise,app_name="法律法规遵守情况")
    if appModel:
        appModel=appModel[0]
    if request.method == "GET":
        try:
            basic_list = Environmental_emergencies.objects.filter(enterprise = _enterPrise,application_status=appModel)
            if len(basic_list) > 0:
                basic = basic_list[0]
                return render_to_response('enterprise/basic_information/laws/basic_laws_emergency.html', {  'basic' : basic } ,context_instance=RequestContext(request))
            else:
                return render_to_response('enterprise/basic_information/laws/basic_laws_emergency.html')
        except Exception as e:
            return HttpResponse("非法请求\n\n"+e.message)
    if request.method == "POST":
        try:
            basic_list = Environmental_emergencies.objects.filter(enterprise = _enterPrise,application_status=appModel)
            if basic_list:
                basic = basic_list[0]
            else:
                basic = Environmental_emergencies()
                #装填菜单
            auto_wear(request,basic,"enterprise_basic_information",'Environmental_emergencies')
                
            basic.enterprise = _enterPrise
            basic.application_status=appModel
            try:
                key= request.GET['key']
                basic.submit_type='2'
                appModel.app_status="未确认"
                appModel.save()
            except Exception as e:
                basic.submit_type='1'
            basic.save()
            return HttpResponseRedirect("/basic/law/detail/")
        except Exception as e:
            result = {'error':e.message if '' else (e.__str__()) }
            return HttpResponse(simplejson.dumps(result))
        else:
            result = {'success':'数据修改成功!' }
            return HttpResponse(simplejson.dumps(result))
    return render_to_response('enterprise/basic_information/laws/basic_laws_emergency.html')